package cn.tedu.file.controller;

import cn.tedu.common.model.RestResult;
import cn.tedu.common.model.RestResultUtils;
import cn.tedu.file.domain.FileVO;
import cn.tedu.file.service.FileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/file")
public class FileController {
    @Autowired
    private FileService fileService;

    @PostMapping("/upload")
    public RestResult<FileVO> uploadFile(MultipartFile file) throws Exception {
        String url = fileService.uploadFile(file);
        FileVO fileVO=new FileVO();
        fileVO.setUrl(url);
        fileVO.setName(file.getOriginalFilename());
        fileService.uploadFile(file);
        return RestResultUtils.success(fileVO);
    }
}
